# -*- coding: UTF-8 -*-
# 作者： 磊
# @Time：2022/5/4
# coding=utf-8
import re
import pytest as pytest
import requests
class TestSecondRequest3:
    access_token=""
    csrf_token=""

    # 这节主要讲cookies的主要传参
    phpwind_cookie=""
    def test_phpwind_start(self):
        url="http://47.107.116.139/phpwind/"
        res=requests.get(url=url)
        return_data=res.text
        obj=re.search('name="csrf_token" value="(.*?)"',return_data)
        TestSecondRequest3.csrf_token=obj.group(1)
        TestSecondRequest3.phpwind_cookie=res.cookies

    # print("csrf_token=",csrf_token)

    #成功不了，密码有误
    def test_login(self):
        print("test_login11111111111=",TestSecondRequest3.csrf_token)
        url="http://47.107.116.139/phpwind/index.php?m=u&c=login&durun"
        data={
            "username":"msxy",
            "password": "msxy",
            "csrf_token": TestSecondRequest3.csrf_token,
            "backurl": "http://47.107.116.139/phpwind/",
            "invite": ""
        }
        headers={
            "Accept":"application/json, text/javascript, */*; q=0.01",
            "X-Requested-With":"XMLHttpRequest"
        }
        #请求的时候要带上cookies，否则无状态登录
        res = requests.post(url=url, data=data,headers=headers,cookies=TestSecondRequest3.phpwind_cookie)
        print("请求头：", res.request.headers)
        print(res.text)
if __name__ == '__main__':
        pytest.main(['-vs',"test03_cookies.py"])




